<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page contentType="text/html; charset=utf-8" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>平台管理系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" type="text/css" href="/css/plugins/dropzone/basic.css"/>
    <link rel="stylesheet" type="text/css" href="/css/plugins/dropzone/dropzone.css"/>
    <link rel="stylesheet" type="text/css" href="/css/plugins/layui-formSelect/formSelects-v4.css"/>
    <link rel="stylesheet" href="/css/plat-style.css">
    <style>
        img {
            margin-left: 5px
        }
    </style>
</head>
<body>
<div class="layui-col-md12">
    <div class="layui-card">

        <div class="layui-col-md-offset11">
            <c:if test="${business.id != null }">
                <button class="layui-btn layui-btn-sm layui-btn-normal" style="margin-top: 5px;"
                        onclick="history.go(-1)">返回上一页
                </button>
            </c:if>
        </div>
        <div class="layui-card-body">
            <div class="layui-tab layui-tab-brief" lay-filter="component-tabs-brief">
                <ul class="layui-tab-title">
                    <li class="layui-this">基本信息</li>
                    <li>商家资料</li>
                    <li lay-id="3">&nbsp;&nbsp;&nbsp;店铺详情&nbsp;&nbsp;&nbsp;</li>
                </ul>
                <div class="layui-tab-content">
                    <div class="layui-tab-item layui-show">
                        <form class="layui-form" id="businessAddForm">
                            <input type="hidden" name="id" value="${business.id}">
                            <input type="hidden" name="fromType" value="2">
                            <input type="hidden" id="onoffVal" value="${business.onOff}">
                            <div class="layui-container">
                                <div class="layui-form-item">
                                    <div class="layui-col-sm1 layui-col-sm-offset2 layui-col-sm8">
                                        <blockquote class="layui-elem-quote">
                                            如果需要变更店铺类型，请谨慎操作；如原类型已为全部，则不允许改变类型。
                                        </blockquote>
                                    </div>
                                </div>
                                <c:if test="${business.onOff != 2}">
                                    <div class="layui-form-item">
                                        <label class="layui-col-sm1 layui-col-sm-offset2"><span
                                                class="red">*&nbsp;</span>店铺范围</label>
                                        <div class="layui-col-sm4">
                                            <select name="onOff" data-type="5">
                                                <option value="">请选择</option>
                                                <c:forEach items="${scopeList}" var="i">
                                                    <option value="${i.id}" ${business.onOff==i.id?'selected':''} >${i.name}</option>
                                                </c:forEach>
                                            </select>
                                        </div>
                                    </div>
                                </c:if>
                                <c:if test="${business.onOff==2}">
                                    <input type="hidden" name="onOff" value="2">
                                </c:if>
                                <div class="layui-form-item" id="online" style="display: none;">
                                    <label class="layui-col-sm1 layui-col-sm-offset2"><span class="red">*&nbsp;</span>线上店铺名称</label>
                                    <div class="layui-col-sm4">
                                        <input type="text" name="nickNameOn" value="${business.nickNameOn}"
                                               class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-form-item" id="offline" style="display: none;">
                                    <label class="layui-col-sm1 layui-col-sm-offset2"><span class="red">*&nbsp;</span>线下店铺名称</label>
                                    <div class="layui-col-sm4">
                                        <input type="text" name="nickName" value="${business.nickName}"
                                               class="layui-input">
                                    </div>
                                </div>
                                <%--                                <div class="layui-form-item">--%>
                                <%--                                    <label class="layui-col-sm1 layui-col-sm-offset2"><span class="red">*&nbsp;</span>企业名称</label>--%>
                                <%--                                    <div class="layui-col-sm4">--%>
                                <%--                                        <input type="text" name="companyName" value="${business.companyName}" class="layui-input">--%>
                                <%--                                    </div>--%>
                                <%--                                </div>--%>
                                <div class="layui-form-item">
                                    <label class="layui-col-sm1 layui-col-sm-offset2"><span class="red">*&nbsp;</span>法人姓名</label>
                                    <div class="layui-col-sm4">
                                        <input type="text" name="realName" value="${business.realName}"
                                               class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-col-sm1 layui-col-sm-offset2"><span class="red">*&nbsp;</span>联系电话</label>
                                    <div class="layui-col-sm4">
                                        <input type="text" name="phone" value="${business.phone}" class="layui-input"
                                               data-type="tip1">
                                    </div>
                                </div>
                                <div class="layui-form-item" id="linkPhone">
                                    <label class="layui-col-sm1 layui-col-sm-offset2"><span class="red">*&nbsp;</span>店铺联系电话</label>
                                    <div class="layui-col-sm4">
                                        <input type="text" name="linkPhone" value="${business.linkPhone}"
                                               class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-col-sm1 layui-col-sm-offset2"><span class="red">*&nbsp;</span>营业执照号</label>
                                    <div class="layui-col-sm4">
                                        <input type="text" name="licenseCode" value="${business.licenseCode}"
                                               class="layui-input">
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <label class="layui-col-sm1 layui-col-sm-offset2"><span class="red">*&nbsp;</span>营业时间</label>
                                    <div class="layui-col-sm4">
                                        <input type="text" name="workTime" autocomplete="off" class="layui-input"
                                               value="${business.workTime}"
                                               data-type="tip4">
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <label class="layui-col-sm1 layui-col-sm-offset2"><span class="red">*&nbsp;</span>店铺简介</label>
                                    <div class="layui-col-sm4">
                                        <input class="layui-input" value="${business.descVal}" name="descVal"
                                               cols="20"/>
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <label class="layui-col-sm1 layui-col-sm-offset2"><span class="red">*&nbsp;</span>让利比例</label>
                                    <div class="layui-col-sm4">
                                        <select name="scale" class="select" data-type="9">
                                            <option value="">请选择</option>
                                            <option ${business.scale=='0.05'?'selected':''} value="0.05">5%</option>
                                            <option ${business.scale=='0.1'?'selected':''} value="0.1">10%</option>
                                            <option ${business.scale=='0.15'?'selected':''} value="0.15">15%</option>
                                            <option ${business.scale=='0.2'?'selected':''} value="0.2">20%</option>
                                            <option ${business.scale=='0.25'?'selected':''} value="0.25">25%</option>
                                            <option ${business.scale=='0.3'?'selected':''} value="0.3">30%</option>
                                            <option ${business.scale=='0.35'?'selected':''} value="0.35">35%</option>
                                            <option ${business.scale=='0.4'?'selected':''} value="0.4">40%</option>
                                            <option ${business.scale=='0.45'?'selected':''} value="0.45">45%</option>
                                        </select>
                                    </div>
                                </div>


                                <div class="layui-form-item" id="linkUrl" style="display: none;">
                                    <label class="layui-col-sm1 layui-col-sm-offset2">&nbsp;&nbsp;&nbsp;&nbsp;链接</label>
                                    <div class="layui-col-sm4">
                                        <input type="text" name="linkUrl" value="${business.linkUrl}"
                                               class="layui-input" placeholder="线下商家选填">
                                    </div>
                                </div>
                                <hr>
                                <div class="layui-form-item">
                                    <label class="layui-col-sm1 layui-col-sm-offset2"><span class="red">*&nbsp;</span>行业类型</label>
                                    <div class="layui-col-sm4">
                                        <select name="industryId" data-type="1" data-click="10">
                                            <option value="">请选择行业</option>
                                            <c:forEach items="${industryList}" var="i">
                                                <option value="${i.id}"
                                                        <c:if test="${business.industryId==i.id}">selected</c:if> >${i.name}</option>
                                            </c:forEach>
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-col-sm1 layui-col-sm-offset2"><span class="red">*&nbsp;</span>营业执照地址</label>
                                    <div class="layui-col-sm2">
                                        <select name="proId" data-type="2" data-click="20">
                                            <option value="0">请选择省份</option>
                                            <c:forEach items="${proList}" var="p">
                                                <option value="${p.id}"
                                                        <c:if test="${business.proId==p.id}">selected</c:if> >${p.name}</option>
                                            </c:forEach>
                                        </select>
                                    </div>
                                    <div class="layui-col-sm2" style="margin-left: 10px">
                                        <select class="address city" name="cityId" data-type="3" data-click="30">
                                            <c:forEach items="${cityList}" var="c">
                                                <option value="${c.id}"
                                                        <c:if test="${business.cityId==c.id}">selected</c:if> >${c.name}</option>
                                            </c:forEach>
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-form-item" style="margin-bottom: 10px">
                                    <div class="layui-col-sm2 layui-col-md-offset3">
                                        <select class="address area" name="areaId">
                                            <c:forEach items="${areaList}" var="a">
                                                <option value="${a.id}"
                                                        <c:if test="${business.areaId==a.id}">selected</c:if> >${a.name}</option>
                                            </c:forEach>
                                        </select>
                                    </div>
                                    <div class="layui-col-sm2" style="margin-left: 10px">
                                        <input type="text" name="addressDetail" value="${business.addressDetail}"
                                               placeholder="详细地址" class="layui-input address">
                                    </div>
                                </div>
                                <div class="layui-form-item" style="margin-bottom: 10px">
                                    <label class="layui-col-sm1 layui-col-sm-offset2"><span class="red">&nbsp;</span>经纬度</label>
                                    <div class="layui-col-sm4">
                                        <input type="text" name="lonlat" value="${business.lonVal},${business.latVal}"
                                               class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-form-item" style="margin-bottom: 80px">
                                    <label class="layui-col-sm1 layui-col-sm-offset2"><span class="red">&nbsp;</span>纬度</label>
                                    <div class="layui-col-sm2">
                                        <input id="copyAddress" type="text" style="display:none;">
                                        &nbsp;<button type="button" class="layui-btn layui-btn-normal"
                                                      data-type="copyAddress">复制商家详细地址
                                    </button>
                                    </div>
                                    <div class="layui-col-sm2">
                                        &nbsp;<a href="https://lbs.amap.com/console/show/picker" target="_blank"
                                                 class="layui-btn layui-btn-warm">打开经纬度查询页</a>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-card-body" style="padding: 15px;"></div>
                            <input type="hidden" name="editFlag" value="2">
                            <textarea hidden id="pcContent" name="content" value="${business.content}"></textarea>
                            <input type="hidden" name="cardFileFront" id="front" value="${business.cardFileFront}">
                            <input type="hidden" name="cardFileBack" id="back" value="${business.cardFileBack}">
                            <input type="hidden" name="busLicense" id="bus" value="${business.busLicense}">
                            <input type="hidden" name="logo" id="logo" value="${business.logo}">
                            <input type="hidden" name="headUrl" id="offLogo" value="${business.headUrl}">
                            <input type="hidden" name="license1" id="pic1" value="${business.license1}">
                            <input type="hidden" name="license2" id="pic2" value="${business.license2}">
                            <input type="hidden" id="brandId" value="${business.brandIds}">
                            <div id="allUrl" hidden="hidden">
                                <c:forEach items="${business.coverUrl}" var="c">
                                    <input type="hidden" name="urls" value="${c}"/>
                                </c:forEach>
                            </div>
                        </form>
                    </div>
                    <div class="layui-tab-item">
                        <form class="layui-form" id="businessFileForm">
                            <div class="layui-container">
                                <div class="layui-form-item">
                                    <label class="layui-col-sm2 layui-col-sm-offset1"><span class="red">*&nbsp;</span>店铺头像</label>
                                    <div class="layui-col-sm4" id="onlineLogo" style="display: none;">
                                        <label for="busLogo"
                                               class="layui-col-sm3 layui-btn layui-btn-sm layui-btn-primary">上传LOGO</label>
                                        <input accept=".jpg,.png,.gif,.jpeg" type="file" style="display:none;"
                                               name="busLogo" id="busLogo" onchange="showImg(this)"/>
                                        <img id="bLogo" src="${business.logo==""?' ':business.logo}" width="100px"
                                             height="100px"/>
                                    </div>
                                    <div class="layui-col-sm4" id="offlineHead" style="display: none;">
                                        <label for="offlineLogo"
                                               class="layui-col-sm3 layui-btn layui-btn-sm layui-btn-primary">线下头像</label>
                                        <input accept=".jpg,.png,.gif,.jpeg" type="file" style="display:none;"
                                               name="offlineLogo" id="offlineLogo" onchange="showImg(this)"/>
                                        <img id="oLogo" src="${business.headUrl==""?' ':business.headUrl}" width="100px"
                                             height="100px"/>
                                    </div>
                                </div>
                                <hr>
                                <div class="layui-form-item">
                                    <label class="layui-col-sm2 layui-col-sm-offset1"><span class="red">*&nbsp;</span>证件照片</label>
                                    <div class="layui-col-sm4">
                                        <label for="frontUrl"
                                               class="layui-col-sm3 layui-btn layui-btn-sm layui-btn-primary">身份证(国徽面)</label>
                                        <input accept=".jpg,.png,.gif,.jpeg" type="file" style="display:none;"
                                               name="frontImg" id="frontUrl"
                                               onchange="showImg(this)"/>
                                        <img id="fImg" src="${business.cardFileFront==""?' ':business.cardFileFront}"
                                             width="200px" height="130px"/>
                                    </div>
                                    <div class="layui-col-sm4">
                                        <label for="backUrl"
                                               class="layui-col-sm3 layui-btn layui-btn-sm layui-btn-primary">身份证(相片面)</label>
                                        <input accept=".jpg,.png,.gif,.jpeg" type="file" style="display:none;"
                                               name="backImg" id="backUrl" onchange="showImg(this)"/>
                                        <img id="bImg" src="${business.cardFileBack==""?' ':business.cardFileBack}"
                                             width="200px" height="130px"/>
                                    </div>
                                </div>
                                <hr>
                                <div class="layui-form-item">
                                    <label class="layui-col-sm2 layui-col-sm-offset1"><span class="red">*&nbsp;</span>营业执照</label>
                                    <div class="layui-col-sm4">
                                        <label for="busUrl"
                                               class="layui-col-sm3 layui-btn layui-btn-sm layui-btn-primary">上传营业执照</label>
                                        <input accept=".jpg,.png,.gif,.jpeg" type="file" style="display:none;"
                                               name="busImg" id="busUrl"
                                               onchange="showImg(this)"/>
                                        <img id="buImg" src="${business.busLicense==""?' ':business.busLicense}"
                                             width="200px" height="130px"/>
                                    </div>
                                </div>
                                <hr>
                                <div class="layui-form-item">
                                    <label class="layui-col-sm2 layui-col-sm-offset1">&nbsp;&nbsp;&nbsp;其它执照</label>
                                    <div class="layui-col-sm4">
                                        <label for="licen1"
                                               class="layui-col-sm3 layui-btn layui-btn-sm layui-btn-primary">上传</label>
                                        <input accept=".jpg,.png,.gif,.jpeg" type="file" style="display:none;"
                                               name="licen1" id="licen1" onchange="showImg(this)"/>
                                        <img id="license1" src="${business.license1==""?' ':business.license1}"
                                             width="200px" height="130px"/>
                                    </div>
                                    <div class="layui-col-sm4">
                                        <label for="licen2"
                                               class="layui-col-sm3 layui-btn layui-btn-sm layui-btn-primary">上传</label>
                                        <input accept=".jpg,.png,.gif,.jpeg" type="file" style="display:none;"
                                               name="licen2" id="licen2" onchange="showImg(this)"/>
                                        <img id="license2" src="${business.license2==""?' ':business.license2}"
                                             width="200px" height="130px"/>
                                    </div>
                                </div>
                                <hr>
                                <div class="layui-form-item" id="coverurl" style="display: none;">
                                    <label class="layui-col-sm2 layui-col-sm-offset1"><span class="red">*&nbsp;</span>店铺门头照</label>
                                    <div class="layui-col-sm8">
                                        <div id="imgDiv" hidden="hidden">
                                            <c:forEach items="${business.coverUrl}" var="p">
                                                <input type="text" hidden name="urls" value="${p }"/>
                                            </c:forEach>
                                        </div>
                                        <div class="layui-col-sm8">
                                            <div id="dropz" class="dropz"></div>
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-card-body" style="padding: 15px;"></div>
                            </div>
                        </form>
                    </div>

                    <div class="layui-tab-item">
                        <div class="layui-card-body">
                            <div class="layui-form-item">
                                <div class="layui-col-sm12">
                                    <textarea id="content" name="content"
                                              style="display: none">${business.content}</textarea>
                                    <script id="articleEditor" type="text/plain"
                                            style="width:100%;height:400px;"></script>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="layui-form-item layui-layout-admin">
                        <div class="layui-col-sm4">
                            <div class="layui-footer" style="left: 0;">
                                <button class="layui-btn" onclick="saveBusinessFile()">保存</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="/layuiadmin/layui/layui.js"></script>
<script type="text/javascript" src="/js/jquery/jquery.min.js"></script>
<script type="text/javascript" src="/js/jquery.form.js"></script>
<script type="text/javascript" src="/js/common.js"></script>
<script type="text/javascript" src="/js/plugins/image/previewImg.js"></script>
<script type="text/javascript" src="/js/plugins/dropzone/dropzone.js"></script>
<script type="text/javascript" src="/js/plugins/layui-formSelect/formSelects-v4.min.js"></script>
<script type="text/javascript" src="/js/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="/js/ueditor/ueditor.all.min.js"></script>
<script type="text/javascript" src="/js/ueditor/lang/zh-cn/zh-cn.js"></script>
<script>
    layui.config({
        //静态资源所在路径
        base: '/layuiadmin/'
    }).extend({
        //主入口模块
        index: 'lib/index'
    }).use(['index', 'form', 'upload'], function () {
        var $ = layui.$, layer = layui.layer, form = layui.form;
        var onoff = $("#onoffVal").val();
        form.on('select', function (data) {
            //得到select原始DOM对象
            var dom = data.elem;
            //得到选择下拉框类型，1为选择行业，2为选择地址
            var selectType = $(dom).data("type");
            //得到点击下拉框类型，10对应行业，20、30对应地址
            //此处是重新选择时需要清空其它下拉框的数据
            var clickType = $(dom).data('click');
            //得到被选中元素的id
            var id = data.value;
            //selectType为1时代表是选择行业
            if (selectType === 1) {
                $.ajax({
                    url: "/product/queryIndustryDetailById",
                    data: {"pid": id},
                    dataType: "json",
                    type: "post",
                    success: function (data) {
                        var html = '<option value="">请选择</option>';
                        $.each(data.data, function (i, v) {
                            html += '<option value="' + v.id + '" >' + v.name + '</option>'
                        });
                        $(".industry").append(html);
                        //重新渲染下拉框元素
                        form.render('select');
                    }
                });
            } else if (selectType === 5) {
                //0线上 1线下 2全部
                if (id == 0) {
                    //线下店铺名称
                    $("#offline").css("display", "none");
                    //线下店铺链接
                    $("#linkUrl").css("display", "none");
                    //线下店铺头像
                    $("#offlineHead").css("display", "none");
                    //线下门头照
                    $("#coverurl").css("display", "none");
                    //线下店铺联系电话
                    $("#linkPhone").css("display", "none");
                    //线上店铺名称
                    $("#online").css("display", "block");
                    //线上店铺头像
                    $("#onlineLogo").css("display", "block");
                } else if (id == 1) {
                    $("#online").css("display", "none");
                    $("#onlineLogo").css("display", "none");
                    $("#offline").css("display", "block");
                    $("#linkUrl").css("display", "block");
                    $("#linkPhone").css("display", "block");
                    $("#offlineHead").css("display", "block");
                    $("#coverurl").css("display", "block");
                } else if (id == 2) {
                    $("#offline").css("display", "block");
                    $("#linkUrl").css("display", "block");
                    $("#offlineHead").css("display", "block");
                    $("#coverurl").css("display", "block");
                    $("#online").css("display", "block");
                    $("#onlineLogo").css("display", "block");
                    $("#linkPhone").css("display", "block");
                }
                form.render();
            }else if (selectType === 9) {
            }else {
                //selectType为2或3一起处理，选择地址下拉框
                $.ajax({
                    url: "/sys/queryAddressNoPage",
                    data: {"pid": id},
                    dataType: "json",
                    type: "post",
                    success: function (data) {
                        var html = '<option value="">请选择</option>';
                        $.each(data.data, function (i, v) {
                            html += '<option value="' + v.id + '" >' + v.name + '</option>'
                        });
                        if (selectType === 2) {
                            //城市
                            $(".city").append(html);
                        } else if (selectType === 3) {
                            //地区
                            $(".area").append(html);
                        }
                        form.render('select');
                    }
                });
            }
            //点击清空其它下拉框事件
            if (clickType === 10) {
                //这里是重新选择行业，需要清空子行业的下拉框
                $(".industry").empty();
            } else if (clickType === 20) {
                //重新选择了省份，清空城市、地区的下拉框
                $(".city").empty();
                $(".area").empty();
            } else if (clickType === 30) {
                //重新选择了城市，清空地区下拉框
                $(".area").empty();
            }
            //渲染表单中下拉框元素
            form.render('select');

        });
        if (onoff == 0) {
            /* 线上 */
            //线下店铺名称
            $("#offline").css("display", "none");
            //线下店铺链接
            $("#linkUrl").css("display", "none");
            //线下店铺头像
            $("#offlineHead").css("display", "none");
            //线下门头照
            $("#coverurl").css("display", "none");
            //线下店铺联系电话
            $("#linkPhone").css("display", "none");
            //线上店铺名称
            $("#online").css("display", "block");
            //线上店铺头像
            $("#onlineLogo").css("display", "block");
        } else if (onoff == 1) {
            /* 线下 */
            $("#online").css("display", "none");
            $("#onlineLogo").css("display", "none");
            $("#offline").css("display", "block");
            $("#linkUrl").css("display", "block");
            $("#linkPhone").css("display", "block");
            $("#offlineHead").css("display", "block");
            $("#coverurl").css("display", "block");
        } else if (onoff == 2) {
            /* 全部 */
            $("#offline").css("display", "block");
            $("#linkUrl").css("display", "block");
            $("#offlineHead").css("display", "block");
            $("#coverurl").css("display", "block");
            $("#online").css("display", "block");
            $("#onlineLogo").css("display", "block");
            $("#linkPhone").css("display", "block");
        }

        var active = {
            tip1: function () {
                layer.tips('请输入正确的手机号码', this, {
                    tips: 2
                });
            },
            tip2: function () {
                layer.tips('请输入15位的营业执照号', this, {
                    tips: 2
                });
            },
            copyAddress: function () {
                var str = $("[name='proId'] option:selected").text() +
                    $("[name='cityId'] option:selected").text() +
                    $("[name='areaId'] option:selected").text() +
                    $("[name='addressDetail']").val();
                var copyAddress = $("#copyAddress")
                copyAddress.val(str);
                copyAddress.show();
                copyAddress.select();
                document.execCommand("Copy");
                copyAddress.hide();
            }
        };
        $('.layui-input').on('focus', function () {
            var type = $(this).data('type');
            active[type] && active[type].call(this);
        });

        $('.layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] && active[type].call(this);
        });


    });


    $(function () {
        /* 富文本编辑器加载 */
        var ue = UE.getEditor('articleEditor');
        UE.Editor.prototype._bkGetActionUrl = UE.Editor.prototype.getActionUrl;
        UE.Editor.prototype.getActionUrl = function (action) {
            if (action == '/uploadFile') {
                return '/base/uploadRichFile';
            } else {
                return this._bkGetActionUrl.call(this, action);
            }
        };
        UE.getEditor('articleEditor').ready(function () {
            UE.getEditor('articleEditor').setContent($("#content").text());
        });
        // layui多选插件加载
        var formSelects = layui.formSelects;
        formSelects.value('label');
    });


    $("#dropz").dropzone({
        url: "/upload/uploadFiles",
        maxFiles: 3,
        maxFilesize: 5,
        acceptedFiles: ".gif,.jpg,.png,.jpeg",
        addRemoveLinks: true,
        dictDefaultMessage: "点击或者拖拽文件以上传",
        init: function () {
            this.emit("initimage", "${business.coverUrl}", "${business.coverUrl}");
            this.on("success", function (file, data) {
                var url = file.previewElement.classList[3];
                $("#imgDiv").append('<input type="text" name="urls" value="' + url + '"/> ');
                $("#allUrl").append('<input type="text" name="urls" value="' + url + '"/> ');
            });
            this.on("removedfile", function (file) {
                var url = file.previewElement.classList[3];
                $("#imgDiv").find("input").each(function (e) {
                    var val = $(this).val();
                    if (url == val) {
                        $(this).remove();
                    }
                });
                $("#allUrl").find("input").each(function (e) {
                    var val = $(this).val();
                    if (url == val) {
                        $(this).remove();
                    }
                });
            });
        }
    });

    function saveBusinessFile() {

        $("#pcContent").text(UE.getEditor('articleEditor').getContent());
        $("#businessFileForm").ajaxSubmit({
            type: 'post',
            url: "/upload/uploadFileBatch",
            data: $("#businessFileForm").serialize(),
            dataType: 'json',
            success: function (data) {
                if (data.status) {
                    for (var key in data.data) {
                        $("#" + key).val(data.data[key]);
                    }
                    saveBusinessEdit();
                } else {
                    layer.msg(data.desc, {icon: 2});
                }
            },
            error: function () {
                layer.msg("图片上传失败", {icon: 2});
            }
        })
    }

    function saveBusinessEdit() {
        $("#businessAddForm").ajaxSubmit({
            type: 'post',
            url: "/business/editBusiness",
            data: $("#businessAddForm").serialize(),
            dataType: 'json',
            success: function (data) {
                if (data.status) {
                    layer.msg(data.desc, {icon: 1});
                    setTimeout(function () {
                        window.location.href = "/business/business";
                    }, 1000)
                } else {
                    layer.msg(data.desc, {icon: 2});
                }
            },
            error: function () {
                layer.msg("请检查页面信息是否正确", {icon: 2});
            }
        });
    }
</script>
</body>
</html>